package com.nineclock.sign.controller;

import com.nineclock.api.sign.SignControllerApi;
import com.nineclock.common.entity.PageResult;
import com.nineclock.common.entity.Result;
import com.nineclock.sign.dto.SignAllUserDTO;
import com.nineclock.sign.dto.SignDTO;
import com.nineclock.sign.dto.SignInfoDTO;
import com.nineclock.sign.dto.SignPCListDTO;
import com.nineclock.sign.service.SignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class SignController implements SignControllerApi {
    @Autowired
    SignService signService;

    /**
     * PC端分页查询签到列表
     * @param startTime
     * @param endTime
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/sign")
    @Override
    public Result<PageResult<SignPCListDTO>> querySignByPage(
            @RequestParam(value = "startTime",required = false) String startTime,
            @RequestParam(value = "endTime",required = false) String endTime,
            @RequestParam("page") Integer page,
            @RequestParam("pageSize") Integer pageSize) {
        PageResult<SignPCListDTO> pageResult = signService.querySignByPage(startTime, endTime, page, pageSize);

        return Result.success(pageResult);
    }

    /**
     * 签到
     *
     * @param signDTO
     * @return
     */
    @PostMapping("/insert")
    @Override
    public Result sign(SignDTO signDTO) {
        signService.sign(signDTO);
        return Result.success();
    }

    /**
     * 获取当天当前用户签到次数
     * @return
     */
    @GetMapping("/getDayCount")
    @Override
    public Result<Integer> queryUserSignCount() {
        Integer count = signService.queryUserSignCount();
        return Result.success(count);
    }

    /**
     * 查询当前用户本月签到记录
     * @param dateStr
     * @return
     */
    @GetMapping("/pagingSignCurrentUserByMonth")
    @Override
    public Result<List<SignDTO>> queryUserMonthSignCount(String dateStr) {
        List<SignDTO> list = signService.queryUserMonthSignCount(dateStr);

        return Result.success(list);
    }

    /**
     * 统计所有企业员工打卡信息
     * @param dateStr 某一时间
     * @return
     */
    @GetMapping("/listSignAllUser")
    @Override
    public Result<List<SignAllUserDTO>> queryAllCompanyUserSignCount(String dateStr) {
        List<SignAllUserDTO> result = signService.queryAllCompanyUserSignCount(dateStr);
        return Result.success(result);
    }

    /**
     * 导出签到列表
     * @param startTime
     * @param endTime
     */
    @GetMapping("/export")
    @Override
    public void export(String startTime, String endTime) {
        signService.export(startTime, endTime);
    }
}
